define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'taobaocoupon/index',
                    add_url: 'taobaocoupon/add',
                    edit_url: 'taobaocoupon/edit',
                    del_url: 'taobaocoupon/del',
                    multi_url: 'taobaocoupon/multi',
                    table: 'taobao_coupon',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'num_iid',
                sortName: 'num_iid',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'num_iid', title: __('Num_iid')},
                        {field: 'appkey_adzone', title: __('Appkey_adzone')},
                        {field: 'q', title: __('Q')},
                        {field: 'cat', title: __('Cat')},
                        {field: 'title', title: __('Title')},
                        {field: 'coupon_amount', title: __('Coupon_amount')},
                        {field: 'shop_title', title: __('Shop_title')},
                        {field: 'me_alert', title: __('Me_alert')},
                        {field: 'me', title: __('Me')},
                        {field: 'item_url', title: __('Item_url'), formatter: Table.api.formatter.url},
                        {field: 'pict_url', title: __('Pict_url'), formatter: Table.api.formatter.url},
                        {field: 'zk_final_price', title: __('Zk_final_price'), operate:'BETWEEN'},
                        {field: 'volume', title: __('Volume')},
                        {field: 'nick', title: __('Nick')},
                        {field: 'user_type', title: __('User_type')},
                        {field: 'seller_id', title: __('Seller_id')},
                        {field: 'category', title: __('Category')},
                        {field: 'coupon_info', title: __('Coupon_info')},
                        {field: 'commission_rate', title: __('Commission_rate'), operate:'BETWEEN'},
                        {field: 'coupon_total_count', title: __('Coupon_total_count')},
                        {field: 'coupon_remain_count', title: __('Coupon_remain_count')},
                        {field: 'coupon_start_fee', title: __('Coupon_start_fee'), operate:'BETWEEN'},
                        {field: 'coupon_start_time', title: __('Coupon_start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'coupon_end_time', title: __('Coupon_end_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'mtime', title: __('Mtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'merid', title: __('Merid')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});